package com.ikas.ai.server.module.appraise.enums;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

/**
 * @Description: 时间趋势类型
 * @Author: qi.yilai
 * @Date: 2023/5/12 14:13
 * @Version: 1.0.0
 **/
public enum ChartTimeTrend implements TimeTrend {

    /**
     * 当天
     */
    D("D") {
        @Override
        public Date startDate() {
            LocalDateTime localDateTime = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
            return Date.from(localDateTime.toInstant(ZoneOffset.ofHours(8)));
        }

        @Override
        public Date endDate() {
            LocalDateTime localDateTime = LocalDateTime.now();
            return Date.from(localDateTime.toInstant(ZoneOffset.ofHours(8)));
        }
    },

    /**
     * 本周
     */
    W("W") {
        @Override
        public Date startDate() {
            LocalDateTime localDateTime = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
            return Date.from(localDateTime.plusDays(localDateTime.getDayOfWeek().getValue() - 1L).toInstant(ZoneOffset.ofHours(8)));
        }

        @Override
        public Date endDate() {
            LocalDateTime localDateTime = LocalDateTime.now();
            return Date.from(localDateTime.toInstant(ZoneOffset.ofHours(8)));
        }
    },

    /**
     * 本月
     */
    M("M") {
        @Override
        public Date startDate() {
            LocalDateTime localDateTime = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0).withDayOfMonth(1);
            return Date.from(localDateTime.toInstant(ZoneOffset.ofHours(8)));
        }

        @Override
        public Date endDate() {
            LocalDateTime localDateTime = LocalDateTime.now();
            return Date.from(localDateTime.toInstant(ZoneOffset.ofHours(8)));
        }
    };

    private String type;

    ChartTimeTrend(String type) {
        this.type = type;
    }

    public static ChartTimeTrend of(String type) {
        for (ChartTimeTrend chartTimeTrend : ChartTimeTrend.values()) {
            if (type.equals(chartTimeTrend.getType())) {
                return chartTimeTrend;
            }
        }
        return null;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}
